<template>
	<view>
		<view class="lover-prattle">
			<text>{{ loverPrattle }}</text>
		</view>
		<view class="copyright">
			<text>晓 · 微情话 by hsowan</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				loveXiao: '宋晓盼，我爱你！',
				loverPrattle: ''
			}
		},
		onLoad() {
			this.handleGetLoverPrattle()
		},
		onPullDownRefresh() {
			this.handleGetLoverPrattle()
		},
		methods: {
			handleGetLoverPrattle() {
				uni.request({
					url: 'https://api.tianapi.com/txapi/saylove/index?key=57a8b8f702253ae8904930b1515adf68',
					success: (res) => {
						if (res.statusCode === 200) {
							const data = res.data
							if (data.code === 200) {
								this.loverPrattle = data.newslist[0].content
							} else {
								this.loverPrattle = this.loveXiao
							}
						} else {
							this.loverPrattle = this.loveXiao
						}
					},
					fail: (err) => {
						console.error(err)
						this.loverPrattle = this.loveXiao
					},
					complete: () => {
						uni.stopPullDownRefresh()
					}
				})
			}
		}
	}
</script>

<style>
	.lover-prattle {
		font-size: 17px;
		text-align: center;
		margin: 200px 10px 0;
	}
	.copyright {
		color: #808695;
		font-size: 15px;
		text-align: center;
		margin-top: 80px;
	}
</style>
